#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int m = 0;
    int top = 0;
    int dop = 0;
    int arr[100000] = { 0 };
    scanf("%d", &m);

    while (m--) {
        char t[10];
        scanf("%s", t);


        if (strcmp(t, "push") == 0) {
            int x = 0;
            scanf("%d", &x);
            arr[top] = x;
            top++;
        }


        else if (strcmp(t, "pop") == 0) {
            if (dop < top) {
                dop++;
            }
        }


        else if (strcmp(t, "empty") == 0) {
            if (top == dop) {
                printf("YES\n");
            }
            else {
                printf("NO\n");
            }
        }


        else if (strcmp(t, "query") == 0) {
            if (top == dop) {
                printf("empty\n");
            }
            else {
                printf("%d\n", arr[dop]);
            }
        }

    }
    return 0;
}